package org.example;

public class Test4 {
    //leetcode 104 二叉树的最大深度 https://leetcode.cn/problems/maximum-depth-of-binary-tree/description/
    public int maxDepth1(TreeNode root) {
        if (root == null) return 0;
        int leftDeepth = maxDepth1(root.left);
        int rightDeppth = maxDepth1(root.right);
        return Math.max(leftDeepth,rightDeppth) + 1;
    }

    public int minDepth(TreeNode root) {
        if (root == null) return 0;
        int leftDeepth = (int)1e5;
        int rightDeepth = (int)1e5;
        if (root.left != null) {
            leftDeepth = minDepth(root.left);
        }
        if (root.right != null) {
            rightDeepth = minDepth(root.right);
        }
        return Math.min(leftDeepth,rightDeepth) + 1;
    }

    public static void main(String[] args) {
        TreeNode a = new TreeNode(2);
        TreeNode b = new TreeNode(3);
        TreeNode c = new TreeNode(4);
        TreeNode d = new TreeNode(5);
        TreeNode e = new TreeNode(6);
        a.right = b;
        b.right = c;
        c.right = d;
        d.right = e;
        Test4 test4 = new Test4();
        test4.minDepth(a);
        System.out.println(777);
    }
}
